struct VertexToPixel
{
    float4 Position     :POSITION;    
    float2 Texture0	:TEXCOORD0;
};

struct PixelToFrame
{	
};

Texture screen;
Texture bump;

sampler screenTexSampler = sampler_state 
{
	texture = <screen> ; 
	magfilter = POINT ; 
	minfilter = POINT ; 
	mipfilter = POINT ; 
	AddressU = mirror;//clamp;//mirror; 
	AddressV = mirror;//clamp;//mirror;
};

sampler screenTexSamplerBump = sampler_state 
{
	texture = <bump> ; 
	magfilter = LINEAR; 
	minfilter = LINEAR; 
	mipfilter = LINEAR; 
	//AddressU = mirror; 
	//AddressV = mirror;
};

float xTime;

////////////////////////////////////
float4 PSSimple(VertexToPixel In) :COLOR0
{    
    return tex2D(screenTexSampler, In.Texture0);
}

technique Simple
{
    pass Pass0
    {        
	CullMode = None;
        VertexShader = null;
        PixelShader = compile ps_2_0 PSSimple();
    }
}

////////////////////////////////////
float4 PSUnderwater(VertexToPixel In) :COLOR0
{    
    float sat = 0.5f - length(In.Texture0 - float2(0.5f, 0.5f));
    float4 blend = float4(0.4f, 0.4f, 0.6f, 1);

    if (sat < 0.001f)
		return tex2D(screenTexSampler, In.Texture0) * blend;
    else {
		sat *= 2;
		float2 wave;
		wave.x = In.Texture0.x + sin(xTime)*sat/11 - cos(0.5f*xTime)*sat/19;
		wave.y = In.Texture0.y + cos(xTime)*sat/13 - sin(0.3f*xTime)*sat/17;
		
		return tex2D(screenTexSampler, wave.xy) * blend;
    }
}

technique Underwater
{
    pass Pass0
    {       
	CullMode = None;
        VertexShader = null;
        PixelShader = compile ps_2_0 PSUnderwater();
    }
}
